<?php

namespace App\Admin\Repositories\Category;

use App\Models\Category\Category as Model;
use Dcat\Admin\Repositories\EloquentRepository;

class Category extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;

    /**
     * 获取树形数据
     */
    public function getTree()
    {
        return $this->model()
            ->orderBy('level')
            ->orderBy('page')
            ->get()
            ->toTree();
    }

    /**
     * 获取顶级分类
     */
    public function getTopCategories()
    {
        return $this->model()
            ->where('parent_id', 0)
            ->orderBy('page')
            ->get();
    }
}
